package com.yidu.StockControl.service.impl;


import com.yidu.StockControl.entity.SecurityInventory;
import com.yidu.StockControl.mapper.SecurityInventoryMapper;
import com.yidu.StockControl.service.SecurityInventoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SecurityInventoryServiceImpl implements SecurityInventoryService {
    @Resource
    SecurityInventoryMapper securityInventoryMapper;


    @Override
    public List<SecurityInventory> selectSecurityInventory(String securityInventoryTime, String securityType, int page, int limit) {
        System.out.println("查询");
        Map map = new HashMap();
        map.put("strWhere",buildWhere(securityInventoryTime,securityType));
        map.put("page",(page-1)*limit);
        map.put("limit",page*limit);
        return securityInventoryMapper.selectSecurityInventory(map);
    }
    public String buildWhere (String securityInventoryTime,String securityType) {
        StringBuffer strWhere = new StringBuffer();

        if (securityInventoryTime!=null && !securityInventoryTime.equals("")){
            strWhere.append(" and securityInventoryTime like '%" + securityInventoryTime +"%'" );
        }
        if (securityType!=null && !securityType.equals("")){
            strWhere.append(" and securityType like '%" + securityType +"%'" );
        }
        return strWhere.toString();
    }

    @Override
    public int insertSecurityInventory(SecurityInventory securityInventory) {
        return securityInventoryMapper.insertSecurityInventory(securityInventory);
    }

    @Override
    public void updateSecurityInventory(SecurityInventory securityInventory) {
        securityInventoryMapper.updateSecurityInventory(securityInventory);
    }

    @Override
    public void deleteSecurityInventory(String securityInventoryId) {
        securityInventoryMapper.deleteSecurityInventory(securityInventoryId);
    }

    @Override
    public int selectSecurityInventoryCount() {
        return securityInventoryMapper.selectSecurityInventoryCount();
    }


}
